package com.example.act6.study.controller;


import com.example.act6.ActReModelFrom.ActReModelFrom;
import com.example.act6.common.entities.CommonResult;
import com.example.act6.study.service.ActivitiModelService;
import org.activiti.engine.repository.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * ActivitiModelController
 * 流程定义模型管理
 * 对流程的部署 有两种方式1.可以通过事先画好的流程图 进行部署。
 * 2.通过创建模型 ，并且通过官方提供的模型制作界面画出流程图 进行部署
 * 说明：第一种 可以通过convertToModel方法 转化成第二种方法
 */
@RestController
@RequestMapping("/model")
public class ActivitiModelController {

    @Autowired
    private ActivitiModelService activitiModelService;

    /**
     * 分页查询
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @PostMapping("/list")
    public CommonResult list(@RequestParam Map<String, Object> params) {
        return CommonResult.ok(activitiModelService.queryPage(params));
    }

    /**
     * 新增模型
     *
     * @param actReModel actReModel
     * @return RestResponse
     */
    @RequestMapping("/save")
    public CommonResult save(@RequestBody ActReModelFrom actReModel) {
        Model model = activitiModelService.add(actReModel);
        return CommonResult.ok(model);
    }

    /**
     * 根据Model部署流程文件
     *
     * @param modelId 标识
     * @return RestResponse
     */
    @RequestMapping("/deploy")
    public CommonResult deploy(String modelId) {
        return CommonResult.ok(activitiModelService.deploy(modelId));
    }

    /**
     * 导出model的xml文件
     *
     * @param id       model标识
     * @param response 响应
     */
    @RequestMapping(value = "/export")
    public void export(String id, HttpServletResponse response) {
        activitiModelService.export(id, response);
    }

    /**
     * 根据主键删除
     *
     * @param ids ids
     * @return RestResponse
     */
    @RequestMapping("/delete")
    public CommonResult delete(@RequestBody String[] ids) {
        activitiModelService.deleteBatch(ids);
        return CommonResult.ok();
    }
}
